package Link

import (
	_ "errors"
)

type QueueLink struct {
	tail  *Node // 尾部
	front *Node // 头部
}

func NewQueueLink() *QueueLink {
	return &QueueLink{}
}

func (ql *QueueLink) length() int {
	tmp := ql.front
	length := 0

	for ql.front != nil {
		tmp = tmp.Pnext
		length++
	}

	return length
}

func (ql *QueueLink) EnQueueLink(data interface{}) {
	newNode := &Node{data, nil}
	if ql.front == nil { //空队列
		ql.front = newNode
		ql.tail = newNode
	} else {
		ql.tail.Pnext = newNode
		ql.tail = ql.tail.Pnext
	}
}

func (ql *QueueLink) DeQueueLink() interface{} {
	if ql.front == nil {
		return nil
	}

	newNode := ql.front
	if ql.front == ql.tail { // 队列总只有一个元素
		ql.front = nil
		ql.tail = nil
	} else {
		ql.front = ql.front.Pnext
	}
	return newNode.data
}
